package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.quasar.hpatient.R;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.context.BaseApp;
import lib.quasar.util.ToastUtil;

/**
 * description: 修改数据, 上下2个, 构成一个区间值
 * created by kalu on 2018/4/16 13:15
 */
public class ChooseTimeDialog extends BaseDialog {


    /****************************************/

    private OnDialogChangeListener listener;

    public ChooseTimeDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_text_double;
    }

    @Override
    protected void initData() {

        findViewById(R.id.dialog_assay_reference_back).setOnClickListener(v -> dismiss());

        findViewById(R.id.dialog_assay_reference_max).setOnClickListener(v -> {
            if (null != listener) {
                listener.onTop();
            }
        });

        findViewById(R.id.dialog_assay_reference_min).setOnClickListener(v -> {
            if (null != listener) {
                listener.onBottom();
            }
        });

        findViewById(R.id.dialog_assay_reference_ok).setOnClickListener(v -> {

            if (null != listener) {

                final TextView text1 = findViewById(R.id.dialog_assay_reference_max);
                final TextView text2 = findViewById(R.id.dialog_assay_reference_min);

                final String trim1 = text1.getText().toString().trim();
                final String trim2 = text2.getText().toString().trim();

                if (!TextUtils.isEmpty(trim1) || !TextUtils.isEmpty(trim2)) {
                    listener.onChange(trim1, trim1);
                }
            }

            dismiss();
        });
    }

    public void setMenuName(String name1, String name2) {

        final TextView text1 = findViewById(R.id.dialog_assay_reference_name1);
        text1.setText(name1);

        final TextView text2 = findViewById(R.id.dialog_assay_reference_name2);
        text2.setText(name2);
    }

    public void setTop(String input) {

        final TextView text1 = findViewById(R.id.dialog_assay_reference_max);
        text1.setText(input);
    }

    public void setBottom(String input) {

        final TextView text1 = findViewById(R.id.dialog_assay_reference_min);
        text1.setText(input);
    }

    private final void toast(int strId) {

        final Context context = BaseApp.getContext();
        final String strs = context.getResources().getString(strId);
        if (TextUtils.isEmpty(strs)) return;

        ToastUtil.showToast(strs);
    }

    public void setOnDialogChangeListener(OnDialogChangeListener mListener) {
        this.listener = mListener;
    }

    public interface OnDialogChangeListener {

        void onChange(String begin, String end);

        void onTop();

        void onBottom();
    }
}
